ProductsIntegrationsResourcesDocumentationPricing
Start Now

© 2026 CapSolver. All rights reserved.

CONTACT US

Slack: lola@capsolver.com

Products

  • reCAPTCHA v2
  • reCAPTCHA v3
  • Cloudflare Turnstile
  • Cloudflare Challenge
  • AWS WAF
  • Browser Extension
  • Many more CAPTCHA types

Integrations

  • Selenium
  • Playwright
  • Puppeteer
  • n8n
  • Partners
  • View All Integrations

Resources

  • Referral System
  • Documentation
  • API Reference
  • Blog
  • FAQs
  • Glossary
  • Status

Legal

  • Terms & Conditions
  • Privacy Policy
  • Refund Policy
  • Don't Sell My Info
Blog/The other captcha/How to solve CAPTCHA With Selenium C#
Jul10, 2024

How to solve CAPTCHA With Selenium C#

Rajinder Singh

Rajinder Singh

Deep Learning Researcher

Introduction

CAPTCHA can often pose a significant obstacle in web scraping and automation tasks. However, with the right approach using Selenium and C#, it's possible to effectively handle and solve CAPTCHA challenges. In this guide, we'll delve into programmatically managing CAPTCHA on websites and demonstrate web scraping on a sample site.

Understanding CAPTCHA

CAPTCHA, short for Completely Automated Public Turing test to tell Computers and Humans Apart, acts like a digital gatekeeper at the entrance of websites. It challenges users with tasks like deciphering distorted text, identifying objects, or listening to audio clips amidst noise. These tests are crucial for safeguarding online services from automated bots, ensuring only genuine human interaction.

For a more detailed exploration of CAPTCHA and its variations, you can check out this comprehensive guide on CAPTCHA types and their effectiveness.

Struggling with the repeated failure to completely solve the irritating captcha? Discover seamless automatic captcha solving with CapSolver AI-powered Auto Web Unblock technology!

Claim Your Bonus Code for top captcha solutions; CapSolver: WEBS. After redeeming it, you will get an extra 5% bonus after each recharge, Unlimited

Prerequisites

Before diving into Selenium and C# for CAPTCHA solving and web scraping, ensure you have the following:

  • Visual Studio
  • .NET Framework
  • Selenium WebDriver for C# (Install using NuGet Package Manager: Install-Package Selenium.WebDriver)
  • WebDriver for your specific browser (e.g., ChromeDriver)

Setting up Selenium in Visual Studio

To get started, create a new C# project in Visual Studio and add Selenium WebDriver using the NuGet Package Manager:

powershell Copy
Install-Package Selenium.WebDriver

Additionally, install the WebDriver for your preferred browser. You can find specific drivers like ChromeDriver and FirefoxDriver for download.

Basic Web Scraping Example

Let's demonstrate how to extract data from a sample website using Selenium in C#:

csharp Copy
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Collections.Generic;

namespace WebScrapingExample
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("https://www.scrapethissite.com/pages/simple/");

            var countries = driver.FindElements(By.CssSelector(".country"));
            List<string> countryData = new List<string>();

            foreach (var country in countries)
            {
                var name = country.FindElement(By.CssSelector(".country-name")).Text;
                var capital = country.FindElement(By.CssSelector(".country-capital")).Text;
                var population = country.FindElement(By.CssSelector(".country-population")).Text;
                var area = country.FindElement(By.CssSelector(".country-area")).Text;

                countryData.Add($"Name: {name}, Capital: {capital}, Population: {population}, Area: {area}");
            }

            foreach (var data in countryData)
            {
                Console.WriteLine(data);
            }

            driver.Quit();
        }
    }
}

Handling CAPTCHA Challenges

Handling CAPTCHA involves integrating a CAPTCHA solving service like CapSolver. Here’s a basic example of how to integrate it:

Setting up CapSolver API Integration

Before solving CAPTCHAs programmatically, you need to sign up on CapSolver's website and obtain an API key.

Step-by-Step Integration with CapSolver

  1. Create an Account: Sign up on the CapSolver website and log in to your dashboard.

  2. Generate API Key: Navigate to the API section in your CapSolver dashboard and generate an API key.

Implementing CAPTCHA Solving with CapSolver

Below is a sample implementation using CapSolver to solve a reCAPTCHA v2 challenge:

csharp Copy
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;

namespace SolveCaptchaExample
{
    class Program
    {
        static async Task Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("https://www.google.com/recaptcha/api2/demo");

            var siteKey = driver.FindElement(By.CssSelector("div.g-recaptcha")).GetAttribute("data-sitekey");
            var pageUrl = driver.Url;

            var captchaResponse = await SolveCaptcha(siteKey, pageUrl, "your apiKey");
            await Console.Out.WriteLineAsync(captchaResponse);


            IWebElement recaptchaResponseElement = driver.FindElement(By.Id("g-recaptcha-response"));
            ((IJavaScriptExecutor)driver).ExecuteScript($"arguments[0].value = '{captchaResponse}';", recaptchaResponseElement);

            IWebElement submitButton = driver.FindElement(By.CssSelector("#recaptcha-demo-submit"));
            submitButton.Click();
        }

        static async Task<string> SolveCaptcha(string siteKey, string pageUrl, string apikey)
        {
            var client = new HttpClient();
            var content = new StringContent($"{{\"clientKey\": \"{apikey}\", \"task\": {{\"type\": \"RecaptchaV2TaskProxyless\", \"websiteURL\": \"{pageUrl}\", \"websiteKey\": \"{siteKey}\"}}}}", System.Text.Encoding.UTF8, "application/json");
            var response = await client.PostAsync("https://api.capsolver.com/createTask", content);
            var jsonResponse = await response.Content.ReadAsStringAsync();
            var taskId = JObject.Parse(jsonResponse)["taskId"].ToString();

            string captchaSolution = "";
            while (captchaSolution == "" || captchaSolution.Contains("processing"))
            {
                await Task.Delay(5000);
                var content2 = new StringContent($"{{\"clientKey\": \"{apikey}\", \"taskId\": \"{taskId}\"}}", System.Text.Encoding.UTF8, "application/json");
                var response2 = await client.PostAsync("https://api.capsolver.com/getTaskResult", content2);
                var jsonResponse3 = await response2.Content.ReadAsStringAsync();
                captchaSolution = JObject.Parse(jsonResponse3)["solution"]["gRecaptchaResponse"].ToString();
            }

            return captchaSolution;
        }
    }
}

Conclusion

In this tutorial, we've covered the basics of using Selenium with C# to handle CAPTCHAs and demonstrated web scraping with a practical example. With these techniques and tools like CapSolver, you can efficiently automate interactions with CAPTCHA-protected websites and extract data seamlessly.

More

The other captchaApr 14, 2026

Can AI Solve CAPTCHA? How Detection and Solve Really Work

Explore how AI detects and solves CAPTCHA challenges, from image recognition to behavioral analysis. Understand the technology behind AI CAPTCHA solvers and how CapSolver aids automated workflows. Learn about the evolving battle between AI and human verification.

Sora Fujimoto
Sora Fujimoto
The other captchaApr 09, 2026

CAPTCHA Solving API Performance Comparison: Speed, Accuracy & Cost (2026)

Compare top CAPTCHA solving APIs by speed, accuracy, uptime, and pricing. See how CapSolver, 2Captcha, CapMonster Cloud, and others stack up in our detailed performance comparison.

Contents

Aloísio Vítor
Aloísio Vítor
The other captchaApr 07, 2026

How to Integrate CAPTCHA Solving API in Python: Step-by-Step Guide

Master how to integrate CAPTCHA solving API in Python with this step-by-step guide. Learn to automate reCAPTCHA, Geetest, and AWS WAF using CapSolver for reliable data extraction.

Aloísio Vítor
Aloísio Vítor
The other captchaApr 03, 2026

Image Recognition API for Custom CAPTCHAs: How It Works in Automation

Discover how an Image Recognition API for custom CAPTCHAs streamlines automation. Learn about AI vision logic, OCR vs. AI, and CapSolver's modular solutions.

Rajinder Singh
Rajinder Singh